package net.zjitc.controller;

import net.zjitc.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/*请求方式：post (get)*/
@Controller
@RequestMapping(value = "/admin")
public class TestController {
    /*返回值常用三种：ModelAndView，void, String:视图 */
  @RequestMapping(value = "/test")
    public ModelAndView test(){
      ModelAndView modelAndView = new ModelAndView();
      modelAndView.addObject("msg","test web....");
      modelAndView.setViewName("/WEB-INF/jsp/first.jsp");
      return modelAndView;
  }

  // mvc-->model view controller
    @RequestMapping(value = "/teststring")
    public String teststring( Model model,User user){
      model.addAttribute("msg","testString web....");
      return "first";//返回视图(web-inf/jsp/**.jsp)
    }

    @RequestMapping(value = "/testredirect")
    public String testredirect(Model model){
        model.addAttribute("msg","testString web....");
        return "redirect:/redirect.jsp";//重定向
    }

    @RequestMapping(value = "/testforward")
    public String testforward(Model model){
        model.addAttribute("msg","forward web....");
        return "forward:teststring";//请求转发
    }


    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public ModelAndView add(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","add web....");
        modelAndView.setViewName("/WEB-INF/jsp/first.jsp");
        return modelAndView;
    }
}
